package com.health.controller;

import com.health.annotation.AdminLog;
import com.health.common.Result;
import com.health.entity.pojo.PageData;
import com.health.entity.pojo.dto.QueryAppointPhysicalDTO;
import com.health.entity.pojo.dto.QueryAppointRegisterByDoctorDTO;
import com.health.entity.pojo.dto.QueryAppointRegisterDTO;
import com.health.entity.pojo.vo.AppointPhysicalDownloadVO;
import com.health.entity.pojo.vo.AppointPhysicalVO;
import com.health.entity.pojo.vo.AppointRegisterDownloadVO;
import com.health.entity.pojo.vo.ApponitmentRegisterVO;
import com.health.service.IAppointmentService;
import com.health.service.IConsultingroomService;
import com.health.util.EasyExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 预约表 前端控制器
 * </p>
 *
 * @author konglz
 * @since 2023-04-16
 */
@Api(tags = "预约管理")
@RestController
@RequestMapping("/appointment")
public class AppointmentController extends BaseController {

    @Autowired
    IAppointmentService appointmentService;

    @Autowired
    IConsultingroomService consultingroomService;

    @PostMapping("/listPageRegisterAppointInfo/{currentPage}/{pageSize}")
    @ApiOperation("分页查询挂号预约信息列表")
    @AdminLog("分页查询挂号预约信息列表")
    public Result listPageRegisterAppointInfo(@PathVariable("currentPage") Integer currentPage, @PathVariable("pageSize") Integer pageSize , @RequestBody QueryAppointRegisterDTO queryAppointRegisterDTO){
        if(currentPage == null) currentPage = 1;
        if(pageSize == null) pageSize = 4;
        return dataResult(appointmentService.listPageRegisterAppointInfo(currentPage, pageSize, queryAppointRegisterDTO));
    }

    @PostMapping("/listPageRegisterAppointByDoctor")
    @ApiOperation("分页查询挂号预约信息明细")
    @AdminLog("分页查询挂号预约明细")
    public Result listPageRegisterAppointByDoctor(@RequestBody QueryAppointRegisterByDoctorDTO queryAppointRegisterByDoctorDTO){
        return dataResult(appointmentService.listPageRegisterAppointByDoctor(queryAppointRegisterByDoctorDTO));
    }

    @GetMapping("/getOneConsultRooms")
    @ApiOperation("获取一级科室")
    @AdminLog("获取一级科室")
    public Result getOneConsultRooms(){
        return dataResult(consultingroomService.getOneConsultRooms());
    }

    @PostMapping("/exportExcel")
    @ApiOperation("导出挂号明细")
    @AdminLog("导出挂号明细")
    public void exportExcel(@RequestBody QueryAppointRegisterByDoctorDTO queryAppointRegisterByDoctorDTO, HttpServletResponse response) throws IOException {
        EasyExcelUtil.download(response,  AppointRegisterDownloadVO.class, appointmentService.listPageRegisterAppointByDoctorDownlaod(queryAppointRegisterByDoctorDTO));
    }

    /**
     *  预约查询体检
     *  @author yu
     *  @since 2023-04-20
     */
    //预约查询体检 数据列表获取
    @PostMapping("/listAllPhysicals/{pageNum}/{pageSize}")
    @ApiModelProperty("预约查询体检 数据列表获取")
    public Result listAllPhysicals(@PathVariable("pageNum") Integer pageNum,
                                   @PathVariable("pageSize") Integer pageSize,
                                   @RequestBody QueryAppointPhysicalDTO dto){
        return this.dataResult(appointmentService.listAllPhysicals(pageNum, pageSize,dto));
    }

    ////预约查询体检 预约明细 基本信息
    @PostMapping("/getPhysicalById/{id}")
    @ApiModelProperty("")
    public Result getPhysicalById(@PathVariable("id") Integer id){
        return this.dataResult(appointmentService.getPhysicalById(id));
    }

    ////预约查询体检 预约明细
    @PostMapping("/getPhysicalOrderById/{pageNum}/{pageSize}/{id}")
    @ApiModelProperty("")
    public Result getPhysicalOrderById(@PathVariable("pageNum") Integer pageNum,
                                        @PathVariable("pageSize") Integer pageSize,
                                        @PathVariable("id") Integer id){
        return this.dataResult(appointmentService.getPhysicalOrderById(pageNum,pageSize,id));
    }

    //导出数据
    @PostMapping("/physicalExcel/{id}")
    public void physicalExcel(@PathVariable("id") Integer id,HttpServletResponse response) throws IOException {
        EasyExcelUtil.download(response,AppointPhysicalDownloadVO.class,appointmentService.listPhysicalDownload(id));
    }
}
